package com.qf.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.ssm.mapper.CustomerOrderMapper;
import com.qf.ssm.po.CarOrder;
import com.qf.ssm.po.Customer;
import com.qf.ssm.service.CustomerOrderService;
import com.qf.ssm.utlis.CommonBeanutils;
import com.qf.ssm.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author chengqiang
 * @Create 2024-01-03-20:38
 * @Description: 租赁记录
 */
@Service
@Repository
public class CustomerOrderServiceImpl implements CustomerOrderService {
    @Autowired
    private CustomerOrderMapper customerOrderMapper;
    // 根据CustomerId搜索
    @Override
    public PageInfo<CustomerOrderVO> queryCustomerOrderByCid(int pageNum, int pageSize, Integer cid){

        // 获取数据并分页
        PageInfo<CustomerOrderVO> pageInfo = CommonBeanutils.convertPageInfo(PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> customerOrderMapper.selectCustomerOrderByCid(cid)),
                new PageInfo<>(), CustomerOrderVO::new);
        // 用车时间字符串处理
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy.MM.dd");
        SimpleDateFormat simpleDateFormat1=new SimpleDateFormat("MM.dd");
        pageInfo.getList().stream().forEach(customerOrder->{
            // 其中把（开始时间和结束时间结合成如2020.12.1~12.7的字符串
            customerOrder.setUseDate(simpleDateFormat.format(customerOrder.getCollectionTime())+"~"+simpleDateFormat1.format(customerOrder.getReturnTime()));
        });

        return pageInfo;
    }
}
